<template>
  <div class="components-container">
    <div class="header-form">
      <div class="layui-inline">
        <label>骨灰堂编号</label>
        <div class="layui-input-inline">
          <el-input v-model="selectData.AssnameLike" placeholder="请输入骨灰堂编号"></el-input>
        </div>
      </div>
      <div class="layui-inline">
        <label class="layui-form-label">逝者姓名</label>
        <div class="layui-input-inline">
          <el-input v-model="selectData.RegnameLike" placeholder="请输入逝者姓名"></el-input>
        </div>
      </div>
       <!-- <div class="layui-inline">
        <label style="margin-left:10px;">开始日期从</label>
        <div class="layui-input-inline">
          <el-date-picker v-date v-model="selectData.AshbegdateGreaterAndEquals" type="date" placeholder="请选择日期" style="width:160px;" /> 到
          <el-date-picker v-date v-model="selectData.AshbegdateLessAndEquals" type="date" placeholder="请选择日期" style="width:160px;" />
        </div>
      </div> -->
      <div class="layui-inline">
        <label class="layui-form-label">寄存状态</label>
        <div class="layui-input-inline">
          <el-select v-model="selectData.AshStatusEquals" placeholder="请选择状态">
            <el-option label="全部" :value="null"></el-option>
            <el-option v-for="item in statusTypes" :key="item.value" :label="item.label" :value="item.value">
            </el-option>
          </el-select>
        </div>
      </div>
      <!-- <el-button type="primary" @click="btnSearch" style="margin-left:20px;">搜索</el-button>
      <el-button @click="btnRepeat">重置</el-button> -->
    </div>
    <div class="header-form" style="margin:10px 0 0 0">
      <div class="layui-inline">
        <label>开始日期从</label>
        <div class="layui-input-inline">
          <el-date-picker v-date v-model="selectData.AshbegdateGreaterAndEquals" type="date" placeholder="请选择日期" style="width:160px;" /> 到
          <el-date-picker v-date v-model="selectData.AshbegdateLessAndEquals" type="date" placeholder="请选择日期" style="width:160px;" />
        </div>
      </div>
      <div class="layui-inline">
        <label style="margin-left:10px;">取出日期从</label>
        <div class="layui-input-inline">
          <el-date-picker v-date v-model="selectData.AshtakdateGreaterAndEquals" type="date" placeholder="请选择日期" style="width:160px;" /> 到
          <el-date-picker v-date v-model="selectData.AshtakdateLessAndEquals" type="date" placeholder="请选择日期" style="width:160px;" />
        </div>
      </div>
      <el-button type="primary" @click="btnSearch" :loading="this.$store.state.isloading" style="margin-left:20px;">搜索</el-button>
      <el-button @click="btnRepeat">重置</el-button>
    </div>
    <!-- 功能列表 -->
    <div>
      <ul class="toolList">
        <li><el-button type="primary" @click="btnSearch" :loading="this.$store.state.isloading">刷新</el-button></li>
        <li v-if="btnShow(item.BTNVALUE)" v-for="(item, index) in $store.state.btnListCommon" @click="operate(item.BTNVALUE)">
          <el-button type="primary" :value="item.BTNSHOWNAME" v-text="item.BTNSHOWNAME"></el-button>
        </li>
      </ul>
    </div>
    <!-- 数据列表 -->
    <dataTable :headList="headList" :dataList="dataList" :pageOrder="pageOrder" @pageChange="pageChange" @selectRow="selectRow"></dataTable>

    <!-- 操作弹窗 -->
    <main-model ref="dialog" @refreshData="getData"></main-model>
    <sweet-modal ref="Print" class="dialog" :sweetModalMaxWidth="pageWidth">
      <h3>{{title}}</h3>
      <iframe :src="printUrl" style="width:1100px; height:500px;margin-top:20px;"></iframe>
    </sweet-modal>
  </div>
</template>
<style rel="stylesheet/scss" lang="scss" scoped>
  @import "src/styles/common.scss";
  .el-button+.el-button {
    margin-left: 0;
  }
  .btnCenter {
    text-align: center;
  }
</style>
<script>
  import sweetModal from "@/components/sweetModal";
  import mainModel from './assUseMain';
  import dataTable from "@/components/Table/DataTable";
  import apiBase from "@/api/apiBase.js";
  import {
    formatDate,
    timeStringToDate
  } from "@/utils/date.js";
  import {
    manage
  } from "@/mixins/managePage.js";
  const ADD = "新增";
  const MODIFY = "修改";
  const DELETE = "删除";
  const INFO = "详情";
  const END = "结束使用";
  const BEG = "开始使用";
  const CONTINUE = "使用续存";
  const REG = "登记";
  export default {
    name: "assUse",
    mixins: [manage],
    data() {
      return {
        pageWidth: 1200,
        selectData: {},
        statusTypes: {},
        printUrl: null,
        title: null,
      };
    },
    methods: {
       //功能操作
      operate(order) {
        this.order = order;
        switch (this.order) {
          case ADD:
            this.$refs.dialog.open(this.order);
            break;
          case REG:
            this.$refs.dialog.open(this.order);
            break;
          case BEG:
            if(this.currentRow && this.currentRow.ASHSTATUS == 'X'){//待寄存处理
              this.$refs.dialog.open('X',this.currentRow);
            }else{
              this.$refs.dialog.open(this.order);
            }
            break;
          case MODIFY:
          case INFO:
          case CONTINUE:
            this.$refs.dialog.open(this.order,this.currentRow);
            break;
          case END:
            this.$refs.dialog.open(this.order,this.currentRow);
            break;
          case DELETE:
            this.dataDelete();
            break;
          case '打印寄存堂登记表':
            this.title = '打印寄存堂登记表'
            this.printOne(this.currentRow.ASHID)
            break;
          case '骨灰寄存证':
            this.title = '骨灰寄存证'
            this.printTwo(this.currentRow.ASHID)
            break;
          default:
        }
      },
      //获取表头
      getCreColumn() {
        let data = {};
        apiBase.DoService(
          data,
          apiBase.getApiAdress().Column.GetAshesUseColumns,
          res => {
            this.headList = res.data.content;
          });
      },
      //获取查询数据
      getData() {
        let Data = JSON.parse(JSON.stringify(this.selectData));
        if (Data.AshbegdateGreaterAndEquals)
          Data.AshbegdateGreaterAndEquals = formatDate(Data.AshbegdateGreaterAndEquals, "yyyyMMdd");
        if (Data.AshbegdateLessAndEquals)
          Data.AshbegdateLessAndEquals = formatDate(Data.AshbegdateLessAndEquals, "yyyyMMdd");
        if (Data.AshtakdateGreaterAndEquals)
          Data.AshtakdateGreaterAndEquals = formatDate(Data.AshtakdateGreaterAndEquals, "yyyyMMdd");
        if (Data.AshtakdateLessAndEquals)
          Data.AshtakdateLessAndEquals = formatDate(Data.AshtakdateLessAndEquals, "yyyyMMdd");
        let data = {
          PageIndex: this.pageOrder.currentPage,
          PageSize: this.pageOrder.pageSize,
          OrderBy: this.pageOrder.orderType,
          OrderByType: this.pageOrder.orderSort,
          Data: Data
        };
        apiBase.DoService(
          data,
          apiBase.getApiAdress().AshesUse.Query,
          res => {
            this.dataList = res.data.content.OutData;
            this.pageOrder.totalNum = res.data.content.RecordCount;
            
          });
      },
      //重置查询
      btnRepeat() {
        this.selectData = {
          
        };
        this.getData();
      },
       // 控制是否显示
      btnShow(val){
       if(val == BEG || val == ADD || val == REG) return true;
       if(this.currentRow){
         if(val == MODIFY || val == DELETE || val == INFO || val == '打印寄存堂登记表' || val == '骨灰寄存证') return true;
         if(this.currentRow.ASHSTATUS === "A" && val == END) return true;
         if(this.currentRow.ASHSTATUS === "A" && val == CONTINUE) return true;
       }
      //  if(this.currentRow.ASHSTATUS === "A"){
      //    if(val == END) return true;
      //  }
       return false;
      },
      //获取状态
      getStatus() {
        let data = {};
        apiBase.DoService(
          data,
          apiBase.getApiAdress().AshesUse.GetAshStatus,
          res => {
            let assTypeData = res.data.content,
              legendsUsersData = assTypeData.map(item => ({
                label: item.Text,
                value: item.Value
              }));
            this.statusTypes = legendsUsersData;
          });
      },
      //删除
      dataDelete() {
        this.$confirm("此操作将永久删除该骨灰堂使用信息, 是否继续?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(callback => {
          var data = {
            ASHID: this.currentRow.ASHID
          };
          apiBase.DoService(
            data,
            apiBase.getApiAdress().AshesUse.Delete,
            res => {
              this.getData();
              this.$message({
                message: this.order + res.data.msg,
                type: "success"
              });
            });
        }).catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除"
          });
        });
      },
      printOne(id) {
        let data = {
          ASHID:id
        };
        apiBase.DoService(
          data, 
          apiBase.getApiAdress().Pdf.PrintAsh,
          res => {
            this.printUrl = res.data.content.PDFNAME;
            this.$refs.Print.open();
          });
      },
      printTwo(id) {
        let data = {
          ASHID:id
        };
        apiBase.DoService(
          data, 
          apiBase.getApiAdress().Pdf.PrintAshCertificate,
          res => {
            this.printUrl = res.data.content.PDFNAME;
            this.$refs.Print.open();
          });
      },
    },
    components: {
      mainModel,
      dataTable,
      sweetModal
    },
    created() {
      this.getCreColumn();
      this.getData();
      this.getStatus();
    
    }
  };
</script>
